import { playerConfig } from "@/config/static";

// 角色部位的位置偏移量
export interface PartOffset {
  x: number;
  y: number;
}

// 角色动作枚举
export enum Action {
  Run = 2, // 奔跑
}

// 角色部位配置
export interface CharacterPartConfig {
  config: {
    sourceX: number; // 部位在精灵图中的X坐标
    sourceY: number; // 部位在精灵图中的Y坐标
    width: number; // 部位宽度
    height: number; // 部位高度
    offset: PartOffset; // 部位相对于角色中心的偏移
    displayWidth: number;
    displayHeight: number;
  };
  name?: string;
  description?: string;
}

// 角色动画帧配置
export interface AnimationFrame {
  body: CharacterPartConfig; // 身体部位的配置
  leftArm?: CharacterPartConfig; // 左手部位的配置
  rightArm?: CharacterPartConfig; // 右手部位的配置
  hair?: CharacterPartConfig; // 发型部位的配置
  hat?: CharacterPartConfig; // 帽子部位的配置
  shirt?: CharacterPartConfig; // 上衣部位的配置
  pants?: CharacterPartConfig; // 裤子部位的配置
}

// 角色配置
export interface CharacterConfig {
  actions: Record<Action, Record<Direction, ActionConfig>>;
}

// 动作配置
export interface ActionConfig {
  frames: AnimationFrame[]; // 动画帧数组
  spriteFramesCount: number; // 精灵图张数
  framesCount: number; // 帧数
  direction?: string; // 方向
}

// 角色方向枚举
export enum Direction {
  Down = 0,
  Right = 1,
  Up = 2,
  Left = 3,
}

/**
 * 默认角色配置
 * @param characterConfig 角色配置
 * @returns 角色动画控制器
 */
export const defaultCharacterConfig: CharacterConfig = {
  actions: {
    [Action.Run]: {
      [Direction.Down]: {
        frames: [
          {
            body: {
              config: {
                sourceX: 602,
                sourceY: 8,
                width: 16,
                height: 29,
                offset: { x: 0, y: 0 },
                displayWidth: 16,
                displayHeight: 29,
              },
            },
            leftArm: {
              config: {
                sourceX: 697,
                sourceY: 21,
                width: 8,
                height: 10,
                offset: { x: -1, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            rightArm: {
              config: {
                sourceX: 705,
                sourceY: 21,
                width: 8,
                height: 10,
                offset: { x: 7, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            pants: {
              config: {
                sourceX: 1159,
                sourceY: 1062,
                width: 12,
                height: 6,
                offset: { x: 1, y: 17 },
                displayWidth: 12,
                displayHeight: 6,
              },
              name: "草裙",
              description: "干草编织的裙子。",
            },
            shirt: {
              config: {
                sourceX: 1320,
                sourceY: 5,
                width: 8,
                height: 8,
                offset: { x: 3, y: 12 },
                displayWidth: 8,
                displayHeight: 8,
              },
              name: "经典背带裤",
              description: "经典的背带裤，适合不同的天气。",
            },
            hair: {
              config: {
                sourceX: 1189,
                sourceY: 5,
                width: 14,
                height: 10,
                offset: { x: 0, y: -2 },
                displayWidth: 14,
                displayHeight: 10,
              },
            },
          },
        ],
        spriteFramesCount: 3,
        framesCount: 30,
        direction: "down",
      },
      [Direction.Right]: {
        frames: [
          {
            body: {
              config: {
                sourceX: 602,
                sourceY: 41,
                width: 16,
                height: 29,
                offset: { x: 0, y: 0 },
                displayWidth: 16,
                displayHeight: 29,
              },
            },
            leftArm: {
              config: {
                sourceX: 705,
                sourceY: 53,
                width: 8,
                height: 10,
                offset: { x: 7, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            rightArm: {
              config: {
                sourceX: 697,
                sourceY: 53,
                width: 8,
                height: 10,
                offset: { x: -1, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            shirt: {
              config: {
                sourceX: 1320,
                sourceY: 13,
                width: 8,
                height: 8,
                offset: { x: 3, y: 12 },
                displayWidth: 8,
                displayHeight: 8,
              },
              name: "经典背带裤",
              description: "经典的背带裤，适合不同的天气。",
            },
            pants: {
              config: {
                sourceX: 1191,
                sourceY: 1062,
                width: 12,
                height: 6,
                offset: { x: 1, y: 17 },
                displayWidth: 12,
                displayHeight: 6,
              },
              name: "草裙",
              description: "干草编织的裙子。",
            },
            hair: {
              config: {
                sourceX: 1188,
                sourceY: 39,
                width: 14,
                height: 10,
                offset: { x: -1, y: -2 },
                displayWidth: 14,
                displayHeight: 10,
              },
            },
          },
        ],
        spriteFramesCount: 3,
        framesCount: 30,
        direction: "right",
      },
      [Direction.Up]: {
        frames: [
          {
            body: {
              config: {
                sourceX: 602,
                sourceY: 73,
                width: 16,
                height: 29,
                offset: { x: 0, y: 0 },
                displayWidth: 16,
                displayHeight: 29,
              },
            },
            leftArm: {
              config: {
                sourceX: 697,
                sourceY: 83,
                width: 6,
                height: 10,
                offset: { x: -1, y: 10 },
                displayWidth: 6,
                displayHeight: 10,
              },
            },
            rightArm: {
              config: {
                sourceX: 705,
                sourceY: 83,
                width: 6,
                height: 10,
                offset: { x: 7, y: 10 },
                displayWidth: 6,
                displayHeight: 10,
              },
            },
            shirt: {
              config: {
                sourceX: 1320,
                sourceY: 29,
                width: 8,
                height: 8,
                offset: { x: 3, y: 11 },
                displayWidth: 8,
                displayHeight: 8,
              },
              name: "经典背带裤",
              description: "经典的背带裤，适合不同的天气。",
            },
            pants: {
              config: {
                sourceX: 1159,
                sourceY: 1062,
                width: 12,
                height: 6,
                offset: { x: 1, y: 17 },
                displayWidth: 12,
                displayHeight: 6,
              },
              name: "草裙",
              description: "干草编织的裙子。",
            },
            hair: {
              config: {
                sourceX: 1188,
                sourceY: 71,
                width: 14,
                height: 10,
                offset: { x: 0, y: -1 },
                displayWidth: 14,
                displayHeight: 10,
              },
            },
          },
        ],
        spriteFramesCount: 3,
        framesCount: 30,
        direction: "up",
      },
      [Direction.Left]: {
        frames: [
          {
            body: {
              config: {
                sourceX: 602,
                sourceY: 41,
                width: 16,
                height: 29,
                offset: { x: 0, y: 0 },
                displayWidth: 16,
                displayHeight: 29,
              },
            },
            leftArm: {
              config: {
                sourceX: 705,
                sourceY: 53,
                width: 8,
                height: 10,
                offset: { x: 7, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            rightArm: {
              config: {
                sourceX: 697,
                sourceY: 53,
                width: 8,
                height: 10,
                offset: { x: -1, y: 12 },
                displayWidth: 8,
                displayHeight: 10,
              },
            },
            shirt: {
              config: {
                sourceX: 1320,
                sourceY: 13,
                width: 8,
                height: 8,
                offset: { x: 3, y: 12 },
                displayWidth: 8,
                displayHeight: 8,
              },
              name: "经典背带裤",
              description: "经典的背带裤，适合不同的天气。",
            },
            hair: {
              config: {
                sourceX: 1188,
                sourceY: 39,
                width: 14,
                height: 10,
                offset: { x: -1, y: -2 },
                displayWidth: 14,
                displayHeight: 10,
              },
            },
            pants: {
              config: {
                sourceX: 1159,
                sourceY: 1062,
                width: 12,
                height: 6,
                offset: { x: 1, y: 17 },
                displayWidth: 12,
                displayHeight: 6,
              },
              name: "草裙",
              description: "干草编织的裙子。",
            },
          },
        ],
        spriteFramesCount: 3,
        framesCount: 30,
        direction: "left",
      },
    },
  },
};
